package com.apts.servise;

import java.util.HashMap;
import java.util.Map;

import com.apts.jfinalbase.BaseJsonPojo;
import com.apts.jfinalbase.BaseServise;
import com.apts.model.TbAdmin;
import com.apts.pojo.ErrorPojo;
import com.apts.pojo.NomalPojo;
import com.apts.util.MD5Util;

/**
 * 后台未登录前业务管理
 * 
 * @author lwh
 * @date 2016-03-20
 */
public class IndexAdminServise extends BaseServise {

	public static final IndexAdminServise Servise = new IndexAdminServise();

	public BaseJsonPojo doLogin(String account, String pwd) {
		TbAdmin admin = TbAdmin.dao.findByAccount(account);
		System.out.println("进入doLogin：" + account);
		// 获取盐值，用户密码加盐后校验
		String pwdsalt = admin.getStr("pwdsalt");
		pwd = MD5Util.md5Encode(pwd + pwdsalt);
		// 判断密码是否正确
		if (admin.getStr("password").equals(pwd)) {
			Map<String, Object> map = new HashMap<String, Object>(0);
			map.put("account", admin.getStr("account"));
			map.put("email", admin.getStr("email"));
			map.put("telephone", admin.getStr("telephone"));
			map.put("picture", admin.getStr("picture"));
			return new NomalPojo(map);
		}

		return new ErrorPojo("用户名或密码错误");
	}
	
	public void register(Map<String, Object> map){
		TbAdmin.dao.register(map);
	}
}
